package algorithm.t202111;

import java.util.Arrays;

/**
 * @author : 李红磊
 * @version :1.0
 * @date : 2021/11/20 9:58
 * @description :3道
 * 领军同学。
 * persevere to last
 * 2021.11.20
 * 2021年11月20日16:00:15
 * 李红磊
 *
 */
public class t20211120 {

    //594.最长和谐子序列
    public int findLHS(int[] nums) {
        if (nums == null || nums.length == 1) return 0;
        int len = nums.length;
        Arrays.sort(nums);
        int slow = 0, fast = 1;
        int res = 0, max, min;
        while (fast < len) {
            max = nums[fast];
            min = nums[slow];
            if (nums[slow] == nums[fast] && fast < len) {
                fast++;
                continue;
            }

            if (max - min == 1) {
                res = Math.max(res, fast - slow + 1);
            } else {

                slow++;
                continue;
            }
            fast++;

        }
        return res;

    }

    //剑指36.二叉搜索树与双向链表
    Node2 head, pre;

    public Node2 treeToDoublyList(Node2 root) {
        if (root == null) {
            return null;
        }
        test(root);
        head.left = pre;
        pre.right = head;

        return head;
    }

    private void test(Node2 root) {
        if (root == null) return;
        test(root.left);
        if (pre != null) pre.right = root;
        else head = root;
        root.left = pre;
        pre = root;
        test(root.right);
    }

    //中序遍历
    private void suffix(TreeNode root) {
        if (root == null) return;

        suffix(root.left);
        suffix(root.right);
        System.out.println(root.val);
    }

    //剑指54.二叉搜索树的第k大节点
    public int kthLargest(TreeNode root, int k) {
        return 0;
    }

    public static void main(String[] args) {
        t20211120 t20211120 = new t20211120();
        int k=2;
        if(--k==1) System.out.println(66666);

        System.out.println("k"+k);
    }


}
